package com.launcher.minecraft;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SettingsActivity extends Activity {
    
    private EditText javaPathEdit;
    private EditText minecraftDirEdit;
    private EditText jvmArgsEdit;
    private EditText windowWidthEdit;
    private EditText windowHeightEdit;
    private Button saveSettingsButton;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
        
        initializeComponents();
        loadSettings();
        setupEventHandlers();
    }
    
    private void initializeComponents() {
        javaPathEdit = findViewById(R.id.java_path_edit);
        minecraftDirEdit = findViewById(R.id.minecraft_dir_edit);
        jvmArgsEdit = findViewById(R.id.jvm_args_edit);
        windowWidthEdit = findViewById(R.id.window_width_edit);
        windowHeightEdit = findViewById(R.id.window_height_edit);
        saveSettingsButton = findViewById(R.id.save_settings_button);
    }
    
    private void loadSettings() {
        // TODO: 从SharedPreferences加载设置
        // 这里只是示例数据
        javaPathEdit.setText("/usr/lib/jvm/java-8-openjdk-amd64/bin/java");
        minecraftDirEdit.setText("/sdcard/games/minecraft");
        jvmArgsEdit.setText("-Xmx2G -Xms1G");
        windowWidthEdit.setText("854");
        windowHeightEdit.setText("480");
    }
    
    private void setupEventHandlers() {
        saveSettingsButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                saveSettings();
            }
        });
    }
    
    private void saveSettings() {
        String javaPath = javaPathEdit.getText().toString();
        String minecraftDir = minecraftDirEdit.getText().toString();
        String jvmArgs = jvmArgsEdit.getText().toString();
        String windowWidth = windowWidthEdit.getText().toString();
        String windowHeight = windowHeightEdit.getText().toString();
        
        // TODO: 保存设置到SharedPreferences
        Toast.makeText(this, "设置已保存", Toast.LENGTH_SHORT).show();
    }
}
